package com.yourname.bank_sim.action;

import com.yourname.bank_sim.DataStore;
import com.yourname.bank_sim.entity.Station;

import java.util.Scanner;

public class StationAction {
    private static Scanner scanner=new Scanner(System.in);
    private static void create(){
        System.out.println("请输入新的车站编号-站名-收费区编号（如：S1-黄山-3）");
        String next = scanner.next();
        String[] splited=next.split("-");
        Station station=new Station();
        station.setId(splited[0]);
        station.setName(splited[1]);
        station.setArea(Integer.parseInt(splited[2]));
        DataStore.addStation(station);
        DataStore.saveData();
    }
    private static void edit(){
        System.out.println("请输入要修改的车站编号：");
        String stationNO = scanner.next();
        System.out.println("新的站名-收费区编号（如：黄山-3）");
        String next = scanner.next();
        String[] splited=next.split("-");
        Station station=new Station();
        station.setId(stationNO);
        station.setName(splited[0]);
        station.setArea(Integer.parseInt(splited[1]));
        DataStore.updateStation(station);
        DataStore.saveData();
    }
    private static void delete(){
        System.out.println("请输入要删除的车站编号：");
        String stationNO = scanner.next();
        DataStore.deleteStation(stationNO);
        DataStore.saveData();
    }
    public static void menu(){
        while (true){
            System.out.println("""
                    1.车站创建
                    2.车站编辑
                    3.车站删除
                    4.退出
                    """);
            int i = scanner.nextInt();
            if (i==4){
                break;
            }
            switch (i){
                case 1->create();
                case 2->edit();
                case 3->delete();
            }
        }
    }
}
